package com.zhuchaooasystem.ui.home.fragment;

import android.support.v7.widget.GridLayoutManager;
import android.view.ViewGroup;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.adapter.holder.OAHolder;
import com.zhuchaooasystem.base.BaseFragment;
import com.zhuchaooasystem.presenter.home.fragment.OAContract;
import com.zhuchaooasystem.presenter.home.fragment.OAPresenter;

import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @author yinsi
 */

public class OAFragment extends BaseFragment<OAPresenter> implements OAContract.View {

    private final int GRID_COLUMN = 3;

    @BindView(R.id.frag_oa_recycle_menu)
    EasyRecyclerView recycle_menu;
    //----
    private List<Map<String, Object>> listMap;
    private RecyclerArrayAdapter adapter;


    @Override
    protected void initVariables() {
        listMap = mPresenter.initMenus();
        //----
    }

    @Override
    protected void initView() {
        //----
        initRecycle();
    }

    private void initRecycle() {
        GridLayoutManager manager = new GridLayoutManager(mContext, GRID_COLUMN);
        recycle_menu.setLayoutManager(manager);
        //----
        recycle_menu.setAdapterWithProgress(adapter = new RecyclerArrayAdapter<Map<String, Object>>(mContext, listMap) {
            @Override
            public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
                return new OAHolder(parent);
            }

        });
        //----
        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                mPresenter.jump(position);
            }
        });
    }

    @Override
    protected void initDataAndLoadData() {

    }

    @Override
    protected OAPresenter getPresenter() {
        return new OAPresenter(mContext, this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_oa;
    }

}
